package com.rongke.damo.medicalrecord.controller;

import com.rongke.biz.service.MedicalRecordManager;
import com.rongke.biz.service.UserManager;
import com.rongke.commons.JsonResp;
import com.rongke.model.MedicalRecords;
import com.rongke.model.User;
import com.rongke.utils.StringUtil;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 精准治疗建议的达摩端入口
 * 
 * @author xiaosen.jxs
 * @version $Id: DamoMedicalAdviceController.java, v 0.1 2017年10月13日 下午10:02:37 xiaosen.jxs Exp $
 */
@RestController
@RequestMapping(value = "/api/damo/medicalAdvice")
@Transactional
public class DamoMedicalAdviceController {
    private static final Logger  log = Logger.getLogger(DamoMedicalAdviceController.class);

    @Autowired
    private UserManager          userManager;

    @Autowired
    private MedicalRecordManager medicalRecordManager;

//    @Autowired
//    private DecisionManager      decisionManager;

    /**
     * 根据登陆者ID查询病历基本信息
     * 
     * @param medicalRecords
     * @return
     */
    @RequestMapping(value = "/generateAdvice", method = RequestMethod.POST)
    public JsonResp generateMedicalAdvice(String phone) {
        log.debug("generateMedicalAdvice");

        try {
            if (StringUtil.isEmpty(phone)) {
                return JsonResp.fa(null);
            }

            User user = userManager.selectByPhone(phone);
            if (null == user) {
                return JsonResp.fa(null);
            }
            String userId = user.getUserId();

            MedicalRecords mrInfo = medicalRecordManager.selectByUserId(userId);
            if (null == mrInfo) {
                return JsonResp.fa(null);
            }

//            AutoAdviceResult result = decisionManager.judge(mrInfo.getId());
            //            AutoAdviceResult result = new AutoAdviceResult();
            //            result.setCheckDesc("建议每3个月进行定期检查");
            //            result.addCheckAdvice("胸部CT");
            //            result.addCheckAdvice("腹部CT");
            //            result.setTreateDesc("根治性手术后建议进行辅助化疗");
            //            result.addTreateAdvice("FOLFIRI");
            //            result.addTreateAdvice("CapeOX");
            return JsonResp.ok();
        } catch (Exception e) {
            log.error("generateMedicalAdvice failed", e);
            return JsonResp.fa(null);
        }
    }
}
